ZS and The Birthday Paradox

Time Limit: 20 Sec Memory Limit: 512 MB

Description

img

Input

img

Output

img

Sample Input

4 3

Sample Output

23 128

HINT

img

Solution

img

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;
typedef long long s64;

const int ONE = 1000005;
const int MOD = 1e6 + 3;

s64 n, k;
s64 num = 0;
s64 Fz = 1, Fm = 1;

int get()
{
int res;char c;
while( (c=getchar())<48 || c>57 );
res=c-48;
while( (c=getchar())>=48 && c<=57 )
res=res*10+c-48;
return res;
}

s64 Quickpow(s64 a, s64 b)
{
s64 res = 1;
while(b)
{
if(b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}

int main()
{
cin>>n>>k;

num = 1;
while((1LL << num) < k) num++;
if(num > n) {printf("1 1"); return 0;}

num = 0;
for(s64 i = k - 1; i >= 1; i >>= 1)
num += (i >> 1);

s64 a = Quickpow(2, n);

Fz = 1;
for(int i = 1; i < k; i++)
{
Fz = (s64)Fz * (a - i + MOD) % MOD;
if(Fz == 0) break;
}
Fm = Quickpow(a, k - 1);

int inv = Quickpow(Quickpow(2, num), MOD - 2);

Fz = (s64)Fz * inv % MOD, Fm = (s64)Fm * inv % MOD;
Fz = (Fm - Fz + MOD) % MOD;


cout<<Fz<<" "<<Fm<<endl;
}